<template>
  <div>
<dog :selldog="list" @doggg="btn"  />
<p >请选择你喜欢的狗：
  <ul>
    <li v-for="(item,index) in likeDog" :key="index"  >{{item}}</li>
  </ul>
</p>
  </div>

</template>

<script>
import Dog from './components/Dog.vue'

export default {
  components: { Dog },
  data () {
    return {
      list: [
        {
          dogImgUrl:
        'http://nwzimg.wezhan.cn/contents/sitefiles2029/10146688/images/21129958.jpg',
          dogName: '博美'
        },
        {
          dogImgUrl:
        'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=1224576619,1307855467&fm=26&gp=0.jpg',
          dogName: '泰迪'
        },
        {
          dogImgUrl:
        'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=2967740259,1518632757&fm=26&gp=0.jpg',
          dogName: '金毛'
        }

      ],
      likeDog: []
    }
  },

  created () {

  },

  methods: {
    btn (e) {
      // console.log(e)
      // console.log(ind)
      const index = this.likeDog.findIndex(item => item === e)
      // const index = this.likeDog.findIndex(item => {
      //   return item === e
      // })
      console.log(index)
      if (index === -1) {
        this.likeDog.push(e)
      }
      if (index !== -1) {
        this.likeDog.splice(index, 1)
      }
      // if (this.likeDog.indexOf(this.likeDog) === -1) {
      //   this.likeDog.push(e)
      // } else {
      //   const index = this.likeDog.findIndex(item => item === e)
      //   this.likeDog.splice(index, 1)
      // }
    }

  }
}
</script>

<style scoped lang='less'>

</style>
